<?php require_once ADMINVIEWPATH.'admin_header.php'; ?>
<?php require_once ADMINVIEWPATH.'admin_menu.php'; ?>
<!-- Page Content -->
            <div class="page-content">
                <!-- Page Breadcrumb -->
                <div class="page-breadcrumbs">
                    <ul class="breadcrumb">
                        <li>
                            <i class="fa fa-home"></i>
                            <a href="#">首页</a>
                        </li>
                        <li>
                            <a href="#">系统设置</a>
                        </li>
                        <li class="active"> 考试安排 </li>
                    </ul>
                </div>
                <!-- Page Body -->
                <div class="page-body">
                    <div class="row">
                        <div class="col-xs-12 col-md-12">
                            <div class="widget">
                                <div class="widget-header ">
                                    <span class="widget-caption">考试列表</span>
                                    <div class="widget-buttons">
                                        <a href="#" data-toggle="maximize">
                                            <i class="fa fa-expand"></i>
                                        </a>
                                        <a href="#" data-toggle="collapse">
                                            <i class="fa fa-minus"></i>
                                        </a>
                                    </div>
                                </div>
                                <div class="widget-body">
                                 <div class="table-toolbar">
                                        <a id="editabledatatable_new" href="javascript:void(0);"  class="edit_account btn btn-default">
                                            创建考试
                                        </a>
                                    </div>
                                    <table class="table table-striped table-bordered table-hover" id="simpledatatable">
                                        <thead>
                                            <tr>
                                                <th>考试ID</th>
                                                <th>考试名称</th>
                                                <th>考试时间</th>
                                                <th>考试部门</th>
                                                <th>考试达标率</th>
                                                <th>创建人</th>
                                                <th>创建时间</th>
                                                <th>状态</th>
                                                <th>操作</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                        <tr>
                                            <?php if(!empty($examinationList)):?>
                                                <?php foreach($examinationList as $key=> $row):?>
                                                    <tr class="gradeX ">
                                                        <td class="center" style="text-align:center;width:90px;"><?php echo $row['examinationID'];?></td>
                                                        <td class="center"><?php echo $row['examinationTitle']?></td>
                                                        <td class="center"><?php echo  $row['examinationTime']?></td>
                                                        <td class="center"><?php echo  $row['name']?></td>
                                                        <td class="center"><?php echo  $row['rate']?></td>
                                                        <td class="center"><?php echo  $row['username']?></td>
                                                        <td class="center"><?php echo  date("Y-m-d H:i:s",strtotime($row['createTime']))?></td>
                                                        <td class="center"><?php echo  $row['status']?></td>
                                                        <td class="center " data_id = "<?php echo $row['examinationID'];?>">
                                                            <?php if($row['status'] == "已考"):?>
                                                                <?php if($row['rateTrue']<1):?>
                                                            <a href="javascript:;" class="edit_account">重考</a>
                                                                    <?php else:?>
                                                                    <a href="javascript:;">已考</a>
                                                                    <?php endif;?>
                                                            <?php else:?>
                                                                <a href="javascript:;" class="cancel_exam">取消考试</a>
                                                            <?php endif;?>
                                                        </td>
                                                    </tr>
                                                <?php endforeach;?>
                                            <?php endif;?>
                                        </tr>
                                        <tr><td colspan="9"><div class="page_links"><?= $page_links?></div></td></tr>
                                        </tbody>

                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- /Page Body -->
            </div>
            <!-- /Page Content -->
<script src="<?php echo STATICURL; ?>js/jquery-2.0.3.min.js"></script>
<script src="<?php echo STATICURL; ?>layer/layer.js"></script>
<?php require_once ADMINVIEWPATH.'admin_footer.php'; ?>

<script>
    $('.edit_account').on('click', function(){
        //iframe窗
        var id = $(this).parent().attr("data_id");
        var title = "重新考试";
        //console.log(id);
        if(id == undefined){
            id = "";
            title = "创建考试";
        }
        console.log(id);
        layer.open({
            type: 2,
            title: title,
            shade: [0.5, '#000'],
            shadeClose: true,
            maxmin: true, //开启最大化最小化按钮
            area: ['550px', '520px'],
            content: '/luckydog/examination/toSetExam?id='+id
        });
    });


    $(document).ready(function() {
        $(".J_del").click(function() {
            var id = $(this).parent().attr("data_id");
            if (confirm("您确定要删除该账号吗？")) {
                $.post("/luckydog/account/delAccount", {"id":id}, function(res) {
                    if (res) {
                        window.location.reload();
                    }else{
                        alert("删除失败");
                    }
                });
            }
        });

        $(".cancel_exam").click(function() {
            var id = $(this).parent().attr("data_id");
            if (confirm("您确定要取消此次考试吗？")) {
                $.post("/luckydog/examination/cancel", {"id":id}, function(res) {
                    if (res.status.code==200) {
                        window.location.reload();
                    }else{
                        alert("取消失败");
                    }
                });
            }
        });

        $(".J_Setstatus").click(function() {
            var id = $(this).parent().attr("data_id");
            var status = $(this).attr("status");
            if(status == 1){
                status = -1;
            }else{
                status = 1;
            }
            $.post("/luckydog/account/setStatus", {"id":id,"status":status}, function(res) {
                if (res) {
                    window.location.reload();
                }else{
                    alert("失败");
                }
            });
        });
    });

</script>


